/*
 * @(#)XfvhdlRulesMemComplementaryFile.java        3.0        2004/09/14
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfvhdl;

import xfuzzy.lang.*;
import java.io.*;

/**
* Clase que genera el fichero complementario con el contenido de la memoria de reglas.
* @author Jos� Mar�a �vila Maireles, <b>e-mail</b>: josavimai@alum.us.es
* @version 3.0
*/
public class XfvhdlRulesMemComplementaryFile {

   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   //			  M�TO_DOS P�BLICOS DE LA CLASE				        
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

   /**
   * M�todo que crea el fichero complementario con el contenido de la 
   * memoria.
   */
   public void createCF(Specification spec) throws IOException {

      XfvhdlRulesMemData contenido =
         new XfvhdlRulesMemData(
            XfvhdlProperties.dir_regl,
            XfvhdlProperties.N,
            XfvhdlProperties.K,
            spec);

      // Generamos un fichero con lo que hay en la memoria de reglas

      String mem = new String();

      for (int i = 0; i < contenido.getLength(); i++) {
         if (XfvhdlProperties.withNull) {
            // Dependiendo del modo de defuzzificaci�n se escribir� el 
            // peso o no.
            if (XfvhdlProperties.calculateWeights == false)
               mem += " "
                  + contenido.getLine(i)
                  + " "
                  + contenido.getValue(i)
                  + "\n";
            else
               mem += " "
                  + contenido.getLine(i)
                  + " "
                  + contenido.getValue(i)
                  + " "
                  + contenido.getWeight(i)
                  + "\n";
         } else {
            // Dependiendo del modo de defuzzificaci�n se escribir� el 
            // peso o no.
            if (contenido.isActive(i)
               && XfvhdlProperties.calculateWeights == false)
               mem += " "
                  + contenido.getLine(i)
                  + " "
                  + contenido.getValue(i)
                  + "\n";
            else if (
               contenido.isActive(i)
                  && XfvhdlProperties.calculateWeights == true)
               mem += " "
                  + contenido.getLine(i)
                  + " "
                  + contenido.getValue(i)
                  + " "
                  + contenido.getWeight(i)
                  + "\n";
         }
      }

      new XfvhdlCreateFile(
         XfvhdlProperties.outputFile + "rulesmem.dat",
         mem);
   }

} // Fin de la clase
